# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jaewon

import datetime

from absl import app

from coin.util.queue.engine import EngineBase, run_engine


class ExampleEngine(EngineBase):
  def __init__(self):
    super().__init__()
    self.set_engine_config(topics=['example_topic'])

  def prepare(self):
    print('prepare() is invoked once all dependencies are ready, before the loop is started.')

  def shutdown(self):
    print('shutdown() is invoked before shutting down.')

  def on_message(self, topic, message):
    print(topic, message)
    self.publish('example_topic_2', str(datetime.datetime.now()).encode('utf-8'))

  def on_ping(self):
    print('ping')

  def on_shutdown_requested(self):
    print('shutdown is requested.')

  def on_publish_error(self, topic, message):
    print('publish error!')

  def on_exception(self, exception):
    print('top level exception')


def main(argv):
  engine = ExampleEngine()
  run_engine(engine)


if __name__ == "__main__":
  app.run(main)
